﻿using System.Windows;
using System.Windows.Input;
using Mammoth.Events;
using Mammoth.Navigations;
using Mammoth.Repositories;
using Mammoth.Services;
using Mammoth.Views.Broadcast;
using Mammoth.Views.Message;
using Mammoth.Views.Option;
using Mammoth.Views.Transaction;

namespace Mammoth.ViewModels
{
    public partial class MainWindowViewModel : WPFViewModelBase
    {
        public IMammothNavigationService NavigationService { get; set; }

        IRepositoryFactory repositoryFactory;

        public MainWindowViewModel(IInputElement dispatcher, IRepositoryFactory repoFactory)
            : base(dispatcher)
        {
            repositoryFactory = repoFactory;
        }

        public void Initialize()
        {
            InitializeNavigation();
        }

        private void InitializeNavigation()
        {
            AddHandler(RoutedEvents.NavigationEvent,
                new RoutedEventHandler<ViewNavigationEventArgs>(NavigationEventHandler));
        }

        private void NavigationEventHandler(object sender, ViewNavigationEventArgs e)
        {
            if (e.Type == NavigationType.Backward)
                NavigationService.NavigateBack();
            else
                NavigationService.Show(e.View, e.Arguments);
        }

        public void Back_Click(object sender, MouseButtonEventArgs e)
        {
            NavigationService.NavigateBack();
        }

        public void Inbox_Click(object sender, MouseButtonEventArgs e)
        {
            NavigationService.Show(typeof(MessageView));
        }

        public void Order_Click(object sender, MouseButtonEventArgs e)
        {
            NavigationService.Show(typeof(TransactionView));
        }

        public void Option_Click(object sender, MouseButtonEventArgs e)
        {
            NavigationService.Show(typeof(OptionForm));
        }

        public void Broadcast_Click(object sender, MouseButtonEventArgs e)
        {
            NavigationService.Show(typeof(BroadcastSubscriberList));
        }
    }
}
